
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <string.h>

#define FILEPATH "/tmp/commchan.bin"
#define NUMINTS  (1000)
#define FILESIZE (NUMINTS * sizeof(int))



int memmapcomchan()
{
    int fd;
    int result;

    char **map;  /* mmapped array of chars(array of chars)<-----Comment needed */

    fd = open(FILEPATH, O_RDWR | O_CREAT | O_TRUNC, (mode_t)0600);
    if (fd == -1) {
	perror("Error opening file for writing");
	exit(EXIT_FAILURE);
    }


    result = lseek(fd, FILESIZE-1, SEEK_SET);
    if (result == -1)
    {
	close(fd);
	perror("Error calling lseek() to 'stretch' the file");
	exit(EXIT_FAILURE);
    }

    result = write(fd, "", 1);
    if (result != 1)
    {
	close(fd);
	perror("Error writing last byte of the file");
	exit(EXIT_FAILURE);
    }


    map = mmap(0, FILESIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
    if (map == MAP_FAILED)
    {
	close(fd);
	perror("Error mmapping the file");
	exit(EXIT_FAILURE);
    }

    return 0;
}